package com.wx.filter;


import com.bean.User;
import com.util.UserUtil;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author: 柏竹
 * @Description: 用户权限设置
 * @Date_Created_in: 2021-05-25 10:25
 * @Modified_By: Sans
 * @Project: 快递e栈
 */

@WebFilter({"/wx/views/*","/wx/index.html","/wx/userInfo.do"})
public class AccessControlFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
    
    }
    
    @Override
    public void doFilter(ServletRequest servletRequest , ServletResponse servletResponse , FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) servletRequest;
        HttpServletResponse resp = (HttpServletResponse) servletResponse;
        
        User wxUser = UserUtil.getWxUser(req.getSession());
        if (wxUser != null){
            filterChain.doFilter(req , resp);
        }else {
            resp.sendRedirect("/wx/500.html");
        }
        
    }
    
    @Override
    public void destroy() {
    
    }
}
